/* A hacked up version of popen for MSDOS. MS-C does not have a popen
	 call, presumably since MSDOS is not multitasking. This simulation
	 simply execs the process with stdout set to a temp file and then
	 opens the temp file for reading.
*/

/*
    Contact info:
    bhepple@freeshell.org
    http://bhepple.freeshell.org

    Copyright (C) 1999-2008 Bob Hepple

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; see the file COPYING.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.

*/

#include <stdio.h>

#define MAXLEN 128

static char tempname[] = "junk6547";

FILE *popen(command, rw)
	char *command, *rw;
{
	char cmd[MAXLEN + 1];
	
	if (strlen(command) > MAXLEN - strlen(tempname) - 1)
		return(NULL);
		
	strncpy(cmd, command, MAXLEN);
	cmd[MAXLEN] = '\0';
	strcat(cmd, ">");
	strcat(cmd, tempname);
	if (system(cmd) != 0)
		return(0);
	return(fopen(tempname, "r"));
}

int pclose(file)
	FILE *file;
{
	return(fclose(file));
}

void zaptmp()
{
	unlink(tempname);
}

/* For emacs:
 * Local Variables:
 * tab-width: 8
 * End:
 */
